<template>
  <!-- 申请修改日志dialog -->
  <el-dialog
    title="申请日志"
    v-model="visible"
    width="50%"
    destroy-on-close
    @closed="$emit('closed')"
  >
    <el-collapse v-model="activeNames" v-loading="loading" v-if="!isEmpty">
      <el-collapse-item title="基本信息" name="1">
        <quote-detail ref="detail" :form="queryData"></quote-detail>
      </el-collapse-item>
      <el-collapse-item title="产品信息" name="2">
        <products
          ref="products"
          :tableData="queryData.products"
          :form="queryData"
        ></products>
      </el-collapse-item>
    </el-collapse>
    <el-empty
      description="没有日志数据"
      v-else
      style="height: 500px"
    ></el-empty>
    <template #footer>
      <el-button
        type="primary"
        plain
        :loading="preLoading"
        @click="prePage"
        :disabled="preDisabled"
        >上一页</el-button
      >
      <el-button
        type="primary"
        plain
        :loading="nextLoading"
        @click="nextPage"
        :disabled="nextDisabled"
        >下一页</el-button
      >
    </template>
  </el-dialog>
</template>

<script>
import quoteDetail from '../quoteDetail/components/quoteDetail.vue'
import products from '../quoteDetail/components/products.vue'
export default {
  emits: ['success', 'closed'],
  data () {
    return {
      visible: false,
      loading: false,
      nextLoading: false,
      preLoading: false,
      preDisabled: false,
      nextDisabled: false,
      activeNames: ['1', '2'],
      queryData: {},
      params: {//获取日志接口参数
        correlationId: '',//主表id
        limit: 1,
        page: 1,
        streamType: 1,//流程类型
      },
      isEmpty: false
    }
  },
  components: {
    quoteDetail,
    products
  },
  mounted () {

  },
  methods: {
    //显示
    open (data) {
      this.visible = true
      this.params.correlationId = data.id
      this.getLog()
    },
    // 获取日志
    async getLog () {
      if (this.params.page == 1) this.preDisabled = true
      this.loading = true
      let { data } = await this.$API.workflow.getLog.get(this.params)
      this.queryData = data[0] ? JSON.parse(data[0].dateDetails) : {}
      let arr = Object.keys(this.queryData)
      console.log(arr)
      if (arr.length == 0) {
        this.isEmpty = true
      } else {
        this.isEmpty = false
      }
      this.loading = false
    },

    // 上一页
    prePage () {
      if (this.params.page > 1) {
        this.preDisabled = false
        this.nextDisabled = false
        this.params.page--
      } else {
        this.preDisabled = true
      }
      this.getLog()
    },
    async nextPage () {
      this.preDisabled = false
      this.params.page++
      this.getLog()

    }

  }
}
</script>

<style lang='scss' scoped>
</style>
